package com.demo.base.security;

import com.demo.utils.MD5Util;
import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.crypto.password.PasswordEncoder;

public class CustomPasswordEncoder implements PasswordEncoder {

    @Override
    public String encode(CharSequence rawPassword) {
        return MD5Util.MD5Encode(String.valueOf(rawPassword));
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {

        Boolean match = encodedPassword.equalsIgnoreCase(encode(rawPassword));
        if (!match) {
            throw new AccountExpiredException("用户名密码错误");
        }

        return match;
    }
}
